package com.kin207.netty;

import java.util.LinkedHashMap;
import java.util.Map;

import com.kin207.netty.config.ServerContext;
import com.kin207.netty.handle.IMessageHandle;
import com.kin207.netty.handle.IMessageHandleAdapter;
import com.kin207.netty.handle.adapter.HeadMessageHandleAdapter;
import com.kin207.netty.msg.parse.SplitMessageParse;
import com.kin207.netty.session.SessionManager;
import com.kin207.netty.tcp.TcpChannelHandlerInitializer;
import com.kin207.netty.tcp.TcpChannelInboundHandler;
import com.kin207.netty.tcp.TcpChannelInitializer;

import io.netty.channel.ChannelHandler;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

public class ServerContextTest2 {

	public static void main(String[] args) {
		ServerContext context = ServerContext.create(ServerContext.class.getResourceAsStream("/conf/test2.cnf"));
		
		SessionManager sessionManager = context.getBean("sessionManager", SessionManager.class);
		
		Map<String,IMessageHandle> handles = context.getBean("messageHandles", Map.class);
		
		IMessageHandleAdapter messageHandleAdapter = context.getBean("headMessageHandleAdapter", IMessageHandleAdapter.class);
		
		System.out.println(messageHandleAdapter);
		
		if(true){
			return;
		}
		
		//messageHandleAdapter.setHandles(handles);
		
		SplitMessageParse messageParse = new SplitMessageParse();
		
		TcpChannelInboundHandler channelInboundHandler = new TcpChannelInboundHandler();
		
		Map<String, ChannelHandler> channelHandlers = new LinkedHashMap();
		//channelHandlers.put("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
		channelHandlers.put("decoder", new StringDecoder());
		channelHandlers.put("encoder", new StringEncoder());
		channelHandlers.put("handler", channelInboundHandler);
		
		TcpChannelInitializer channelInitializer = new TcpChannelInitializer();
		channelInitializer.setInitHandles(channelHandlers);
		channelInitializer.setChannelHandlerInitializer(new TcpChannelHandlerInitializer());
		
		
		
		
	}

}
